﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICarPool.DAL.Interface;
using ICarPool.DAL.Sql;
using ICarPool.DAL.Oracle;
using ICarPool.DBCommon;

namespace ICarPool.DAL.Factory
{
    /// <summary>
    /// 静态工厂类，用于生成各种DAO。
    /// </summary>
    public static class DAOFactory
    {
        #region 变量
        private static object synObject = new object();

        private static IDAOUser user = null;
        #endregion

        /// <summary>
        /// 获取用户数据访问对象
        /// </summary>
        /// <returns></returns>
        public static IDAOUser GetDAOUser()
        {
            if (user == null)
            {
                lock (synObject)
                {
                    if (user == null)
                    {
                        //Create user
                        //string dbType = ConfigurationManager.AppSettings["dbType"].ToString();
                        string dbType = DBUtility.GetAppSettingByKey(@"dbType");
                        user = Activator.CreateInstance(Type.GetType(string.Format("ICarPool.DAL.{0}.CarPoolUserDAO,ICarPool.DAL.{0}", dbType), false, true), true) as IDAOUser;
                    } 
                }   
            }

            return user;
        }
    }
}
